package com.kid.lib.word;

import com.kid.modules.utils.system.Loggers;

public class WordUtil {
	/**
	 * 将签名图片添加到文档的底部
	 * 
	 * @param docPath
	 *            需要添加签名图片的文档
	 * @param imagePath
	 *            签名图片路径
	 */
	public static void addNameSignEnd(String docPath, String imagePath) {
		WordBean wb = null;
		try {
			wb = new WordBean();
			wb.startWordApp();
			wb.openDoc(docPath);
			wb.insertJpeg(imagePath, 2);
			wb.saveDoc();
			wb.closeDoc();
		} catch (Throwable t) {
			String msg = String.format(
					"Add singImage \"%s\" to doc \"%s\" error:", imagePath,
					docPath);
			Loggers.docAction.error(msg, t);
		} finally {
			if (wb != null) {
				wb.quitWordApp();
			}
		}
	}

	/**
	 * @param docPath
	 *            需要添加签名图片的文档
	 * @param imagePath
	 *            签名图片路径
	 * @param signFlag
	 *            签名标志
	 */
	public static void addNameSignFixed(String docPath, String imagePath,
			String signFlag) {
		WordBean wb = null;
		try {
			wb = new WordBean();
			wb.startWordApp();
			wb.openDoc(docPath);
			while (wb.find(signFlag)) {
				wb.insertJpeg(imagePath, 0);
			}
			wb.saveDoc();
			wb.closeDoc();
		} catch (Throwable t) {
			String msg = String.format(
					"Add singImage \"%s\" to doc \"%s\" error:", imagePath,
					docPath);
			Loggers.docAction.error(msg, t);
		} finally {
			if (wb != null) {
				wb.quitWordApp();
			}
		}
	}
}
